package cn.lingyangwl.agile.system.service.impl;

import cn.lingyangwl.agile.system.service.SysMenuService;
import cn.lingyangwl.agile.system.service.SysPermissionService;
import cn.lingyangwl.agile.system.service.SysRoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashSet;
import java.util.Set;

/**
 * @author shenguangyang
 */
@Service
public class SysPermissionServiceImpl implements SysPermissionService {
    @Resource
    private SysRoleService roleService;

    @Resource
    private SysMenuService menuDataService;

    @Override
    public Set<String> listUserRolePermission(Boolean isAdmin, Long userId) {
        Set<String> roles = new HashSet<>();
        // 管理员拥有所有权限
        if (isAdmin) {
            roles.add("admin");
        } else {
            roles.addAll(roleService.listRolePermission(userId));
        }
        return roles;
    }

    @Override
    public Set<String> getMenuPermission(boolean isAdmin, Long userId) {
        Set<String> perms = new HashSet<>();
        // 管理员拥有所有权限
        if (isAdmin) {
            perms.add("*:*:*");
        } else {
            perms.addAll(menuDataService.listMenuPermsByUserId(userId));
        }
        return perms;
    }
}
